//
//  HotDesCell.m
//  MyTrip
//
//  Created by zhang on 15/8/29.
//  Copyright (c) 2015年 张益. All rights reserved.
//

#import "HotDesCell.h"
#import "StarView.h"
#import "UIImageView+WebCache.h"
#import "DKNightVersion.h"

@implementation HotDesCell

- (void)dealloc
{
    [_recImage release];
    [_wishLabel release];
    [_commentLabel release];
    [_introLabel release];
    [_star release];
    [_titleLabel release];
    [_picView release];
    [super dealloc];
}

- (instancetype) initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self ceeateView];
    }
    return self;
}

- (void)ceeateView{
    [DKNightVersionManager addClassToSet:self.class];
    self.nightBackgroundColor = UIColorFromRGB(0x343434);
    self.picView = [[[UIImageView alloc] initWithFrame:CGRectMake(5 * OffWidth, 5 * OffHeight, 110 * OffWidth, 110 * OffHeight)] autorelease];
    [self.contentView addSubview:_picView];
    
    self.titleLabel = [[[UILabel alloc] initWithFrame:CGRectMake(_picView.frame.size.width + _picView.frame.origin.x + 5 * OffWidth, 5 * OffHeight, self.frame.size.width - _picView.frame.size.width - 10 * OffWidth, 25 * OffHeight)] autorelease];
    [self.contentView addSubview:_titleLabel];
    
    self.star = [[StarView alloc] initWithFrame:CGRectMake(_picView.frame.size.width + _picView.frame.origin.x + 5, _titleLabel.frame.size.height + _titleLabel.frame.origin.y, 90 * OffWidth, 20 * OffHeight)];
    [self.contentView addSubview:_star];
    
    self.commentLabel = [[[UILabel alloc] initWithFrame:CGRectMake(_star.frame.size.width + _star.frame.origin.x, _titleLabel.frame.size.height + _titleLabel.frame.origin.y, self.frame.size.width - _picView.frame.size.width - 10 * OffWidth - _star.frame.size.width, 20 * OffHeight)] autorelease];
    [self.contentView addSubview:_commentLabel];
    
    self.introLabel = [[[UILabel alloc] initWithFrame:CGRectMake(_picView.frame.size.width + _picView.frame.origin.x + 5 * OffWidth, _star.frame.size.height + _star.frame.origin.y, self.frame.size.width - _picView.frame.size.width - 10 * OffWidth, 40 * OffHeight)] autorelease];
    [self.contentView addSubview:_introLabel];
    
    self.wishLabel = [[UILabel alloc] initWithFrame:CGRectMake(_picView.frame.size.width + _picView.frame.origin.x + 5 * OffWidth, _introLabel.frame.size.height + _introLabel.frame.origin.y + 5, self.frame.size.width - _picView.frame.size.width - 10 * OffWidth, 25 * OffHeight)];
    
    [self.contentView addSubview:_wishLabel];
}

- (void)setValueWithDic:(NSDictionary *)dic{
    NSArray *array = [dic objectForKey:@"tips"];
    NSDictionary *rate = [array firstObject];
    [_picView sd_setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"cover_s"]] placeholderImage:[UIImage imageNamed:@"zhanweitu.jpg"]];
    [_titleLabel setText:[dic objectForKey:@"name"]];
//    [_star setStarNum:[[rate objectForKey:@"rating"] integerValue]];
    [_star createViewWithStarNum:[[rate objectForKey:@"rating"] integerValue]];
    [_commentLabel setText:[NSString stringWithFormat:@"%ld 点评", [[dic objectForKey:@"tips_count"] integerValue]]];
    [_commentLabel setAlpha:0.5];
    [_commentLabel setFont:[UIFont systemFontOfSize:13]];
   
    NSNull *nu = [NSNull null];
    if ([dic objectForKey:@"recommended_reason"] != nu) {
        [_introLabel setText:[dic objectForKey:@"recommended_reason"]];
        [_introLabel setFont:[UIFont systemFontOfSize:13]];
        _introLabel.adjustsFontSizeToFitWidth = YES;
        _introLabel.numberOfLines = 3;
        [_introLabel setAlpha:0.5];
    }
    [_wishLabel setText:[NSString stringWithFormat:@"%ld 人去过", [[dic objectForKey:@"visited_count"] integerValue]]];
    [_wishLabel setFont:[UIFont systemFontOfSize:13]];
    [_wishLabel setAlpha:0.5];
    
}



@end
